#! /usr/bin/perl

# perl script that takes STDIN from a pipe and saves it as a 
# web page. I use this on our log host to share logs around the 
# house via a URL
#
# Author: Nathan Hubbard
# URL: http://code.google.com/p/n8foo
# -------------------------------------------------------------------------


# put this script in your path somewhere.
# define the variables below to set up where the web reports land
# and the CSS that it uses for style

# user config
$url = "http://yourserver/";
$css = "$url/css/webreport.css";
$webpath = "/var/www/html";
$reportpath = "report";
$report = "$webpath/$reportpath/$epoch.html";

# do not edit below this line

# set up times
$epoch = time();
$humantime = humanTime();

# read in STDIN and print it back out
@output = <STDIN>;
print @output;

open(REPORT,">>$report");
print REPORT qq(
<HTML>
<head>
    <title>report $epoch</title>
</head>
<body>
<link rel="StyleSheet" href="$css" type="text/css" media="screen" />
<div class="INFO">
This report created $humantime CST
</div>
<div class="OUTPUT">
<pre>
);

print REPORT @output;

print REPORT qq(
</pre>
</div>
</body>
</html>
);

close(REPORT);

print "\n\n report available at $url/$reportpath/$epoch.html\n\n";


sub humanTime() {
    @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
    @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
    ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
    $year = 1900 + $yearOffset;
    $theTime = "$hour:$minute $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
    return($theTime)
}

